<!DOCTYPE html>
<html>
<head>
    <title>源码管理</title>
    <link rel="stylesheet" href="__STATIC__/js/layui-v2.5.5/css/layui.css">
</head>
<body>
	<!-- layui-tab开始 -->
	<div class="layui-tab " lay-filter="demo-tab">
	
		<div class="layui-card">
			<div class="layui-card-body layui-nopadding " >
				<div class="layui-form-item">
					<label class="layui-form-label">上传源码</label>
					<div class="layui-input-block">
						<input type="text" name="name" lay-verify="name" style="cursor:pointer;" readonly autocomplete="off" id="upload-btn" placeholder="点击此处上传文件 ，只支持zip" class="layui-input">
					</div>
					
				</div>
				<table class="layui-table">
					  <thead>
						<tr>
						  <th>文件名</th>
						  <th>上传时间</th>
						  <th>作者</th>
						  <th>备注</th>
						  <th width="120">操作</th>
						</tr> 
					  </thead>
					  <tbody>
						<volist name="list" id="vo">
						    <tr>
								<td>{$vo.file_name}<?php if($key==0) echo '<span style="color:red;">(最新)</span>';?></td>
								<td>{$vo.add_time}</td>
								<td>{$vo.author}</td>
								<td>{$vo.remarks|default=''}</td>
								<td>
									<div class="layui-btn-group">
										<button type="button" class="layui-btn layui-btn-primary layui-btn-xs remark-btn" data-tag="{$vo->id}" title="备注">
											<i class="layui-icon">&#xe621;</i>
										</button>
										<a href="/{$vo.url}"><button type="button" class="layui-btn layui-btn-primary layui-btn-xs upload-btn" data-tag="{$vo->id}" title="下载">
											<i class="layui-icon">&#xe601;</i>
										</button></a>
										<if condition="$key!=0">
										<a href="/{$vo.url}"><button type="button" class="layui-btn layui-btn-primary layui-btn-xs <?php if($key==0){ echo 'layui-btn-disabled';}else {echo 'mr-btn';}?> " data-tag="{$vo->id}" title="设置为默认">
											<i class="layui-icon">&#xe604;</i>
										</button></a>											
										<button type="button" class="layui-btn layui-btn-primary layui-btn-xs  <?php if($key==0){ echo 'layui-btn-disabled';}else {echo 'delete-btn';}?> " data-tag="{$vo->id}" title="删除">
											<i class="layui-icon">&#xe640;</i>
										</button>
										</if>
									</div>
								</td>
								
							</tr>
						</volist>
					  </tbody>
				</table>
							
			</div>
		</div>
	</div>
	<!-- layui-tab结束-->
<script src="__STATIC__/js/jquery.js"></script>
<script src="__STATIC__/js/layui-v2.5.5/layui.all.js"></script>
<script type="text/javascript">
	;!function(){
		var form = layui.form
			,layer = layui.layer    //弹出层必需
			,layedit = layui.layedit  //富文本必需
			,laydate = layui.laydate  //日期选择必需
			,table = layui.table  //表格必需
			,element = layui.element  //选项卡	
			,upload = layui.upload;
			
		$( '.remark-btn' ).on( 'click' , function(){
			let id = $(this).data('tag');
			let _this = $( this );
			layer.prompt({
				formType:2,
				value:_this.parents('tr').find('td:eq(3)').text(),
				title:'备注',
			},function(value, index, elem){
			  
				  $.post( '{:url("ModuleManage/update")}' , {id:id , value:value } , function( res ){
					let icon = ( res.code == 200 ) ? 1 : 5 ;
					layer.msg( res.message , { icon:icon , time:800 } , function(){
						if( icon == 1 ) {
							window.location.reload();
						}
					} );
				});

			});
			
		} );
			
			//监听提交
		form.on('submit(demo1)', function(data){
			$.post( '{:url("ModulePlugin/addPluginPost")}' , data.field, function( res ){
				let icon = ( res.code == 200 ) ? 1 : 5 ;
				layer.msg( res.message , { icon:icon , time:800 } , function(){
					if( icon == 1 ) {
						parent.location.reload();
						parent.layer.closeAll();
					}
				} );
			});
			return false;
		});
		
		//上传ui图
			upload.render({ 
				elem: '#upload-btn'
				,url: "{:url('ModuleManage/uploadres')}?id={$id}&type={$type}"
				,accept: 'file' //普通文件
				,exts: "zip" //只允许上传压缩文件
				,done: function( res ){
					layer.msg( res.message , { icon:(res.code==200)?1:5 , time:1000} ,function(){
						if( res.code == 200 ){
							window.location.reload();
						}
					} );
				}
			});
			
			$('.delete-btn').click(function(){
				let id = $( this ).data('tag');
				layer.confirm( '确定要删除此文件吗？' , { title: "删除提示" , icon:3 } ,function(){
					$.get( '{:url("ModuleManage/delresource")}?id='+ id+"&type={$type}", function( res ){
						layer.msg( res.message , {icon:(res.code==200 )?1:5 , time:800 } , function(){
							if( res.code == 200 ){
								window.location.reload();
							}
						} );
					 	
					}  );
				} );
			});
			
			
			$('.mr-btn').click(function(){
				let id = $( this ).data('tag');
				layer.confirm( '确定要设置为默认文件吗？' , { title: "设置默认文件提示" , icon:3 } ,function(){
					$.get( '{:url("ModuleManage/setMr")}?id='+ id+"&type={$type}&mid={$id}", function( res ){
						layer.msg( res.message , {icon:(res.code==200 )?1:5 , time:800 } , function(){
							if( res.code == 200 ){
								window.location.reload();
							}
						} );
					 	
					}  );
				} );
			});
 
	}();
	
	var callback = function( index ){
		$( '#add_submit_btn' ).click();
	}
	
	
</script>


</body>
</html>